import Vue from 'vue'
import Router from 'vue-router'

// 初始路由集
const layout = () => import('../components/layout'),
    home = () => import('../page/home'),
    my = () => import('../page/my'),
    apply = () => import('../page/appointment'),
    register = () => import('../page/register'),
    editRegister = () => import('../page/edit-register'),
    code = () => import('../page/health-code'),
    punchCard = () => import('../page/punch-card'),
    uploadCardId = () => import('../page/upload-cardid'),
    patient = () => import('../page/patient'),
    chaperone = () => import('../page/chaperone'),
    addChaperone = () => import('../page/add-chaperone'),
    visitors = () => import('../page/visitors'),
    visitorsApply = () => import('../page/visitors-apply'),
    messageList = () => import('../page/message-list'),
    patientVisitors = () => import('../page/patient-visitors'),
    patientBind = () => import('../page/patient-bind'),
    constantRouterMap = [
        {
            path: '/',
            name: 'index',
            redirect: '/home',
            component: layout,
            children: [
                {
                    path: '/home',
                    name: 'home',
                    component: home,
                    meta: {
                        title: '首页',
                        keepAlive: false
                    }
                },
                {
                    path: '/my',
                    name: 'my',
                    component: my,
                    meta: {
                        title: '我的',
                        keepAlive: false
                    }
                },
                {
                    path: '/register',
                    name: 'register',
                    component: register,
                    meta: {
                        title: '个人注册',
                        keepAlive: false
                    },
                    children: [
                        {
                            path: 'uploadCardId',
                            component: uploadCardId,
                            meta: {
                                title: '上传身份证照片',
                                keepAlive: false
                            }
                        }
                    ]
                },
                {
                    path: '/edit-register',
                    name: 'editRegister',
                    component: editRegister,
                    meta: {
                        title: '个人信息修改',
                        keepAlive: false
                    },
                    children: [
                        {
                            path: 'uploadCardId',
                            component: uploadCardId,
                            meta: {
                                title: '上传身份证照片',
                                keepAlive: false
                            }
                        }
                    ]
                },
                {
                    path: '/apply',
                    name: 'apply',
                    component: apply,
                    meta: {
                        title: '预约申请',
                        keepAlive: false
                    },
                    children: [
                        {
                            path: 'uploadCardId',
                            component: uploadCardId,
                            meta: {
                                title: '上传身份证照片',
                                keepAlive: false
                            }
                        }
                    ]
                },
                {
                    path: '/code',
                    name: 'code',
                    component: code,
                    meta: {
                        title: '查看健康码',
                        keepAlive: false
                    }
                },
                {
                    path: '/punchCard',
                    name: 'punchCard',
                    component: punchCard,
                    meta: {
                        title: '健康打卡',
                        keepAlive: false
                    }
                },
                {
                    path: '/patient',
                    name: 'patient',
                    component: patient,
                    meta: {
                        title: '患者',
                        keepAlive: false
                    }
                },
                {
                    path: '/patient-visitors',
                    name: 'patientVisitors',
                    component: patientVisitors,
                    meta: {
                        title: '全部探视',
                        keepAlive: false
                    }
                },
                {
                    path: '/patient-add',
                    name: 'addChaperone',
                    component: addChaperone,
                    meta: {
                        title: '添加陪护',
                        keepAlive: false
                    },
                    children: [
                        {
                            path: 'uploadCardId',
                            component: uploadCardId,
                            meta: {
                                title: '上传身份证照片',
                                keepAlive: false
                            }
                        }
                    ]
                },
                {
                    path: '/patient-bind',
                    name: 'patientBind',
                    component: patientBind,
                    meta: {
                        title: '关联患者',
                        keepAlive: false
                    },
                    children: [
                        {
                            path: 'uploadCardId',
                            component: uploadCardId,
                            meta: {
                                title: '上传身份证照片',
                                keepAlive: false
                            }
                        }
                    ]
                },
                {
                    path: '/chaperone',
                    name: 'chaperone',
                    component: chaperone,
                    meta: {
                        title: '陪护',
                        keepAlive: false
                    }
                },
                {
                    path: '/visitors',
                    name: 'visitors',
                    component: visitors,
                    meta: {
                        title: '探视',
                        keepAlive: false
                    }
                },
                {
                    path: '/visitors-apply',
                    name: 'visitorsApply',
                    component: visitorsApply,
                    meta: {
                        title: '探视申请',
                        keepAlive: false
                    }
                },
                {
                    path: '/message-list',
                    name: 'messageList',
                    component: messageList,
                    meta: {
                        title: '消息列表',
                        keepAlive: false
                    }
                }
            ]
        }
    ]

let router = new Router({
    // mode: 'history',
    routes: constantRouterMap
})

// 路由跳转前更改网页标题
router.beforeEach((to, from, next) => {
    // if (to.meta && to.meta.title) {
    //     document.title = to.meta.title
    // }
    next()
})

Vue.use(Router)

export default router
